package com.eling.elcms.cater.service.impl;

import com.eling.elcms.cater.dao.IMealRecordDao;
import com.eling.elcms.cater.model.MealRecord;
import com.eling.elcms.cater.model.TravelAccountFlow;
import com.eling.elcms.cater.model.view.MealRecordDetailView;
import com.eling.elcms.cater.model.view.MealRecordView;
import com.eling.elcms.cater.model.view.OrderDishesView;
import com.eling.elcms.cater.service.IMealRecordService;
import com.eling.elcms.cater.service.ITravelAccountFlowService;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MealRecordServiceImpl extends GenericManagerImpl<MealRecord, Long> implements IMealRecordService{
	
	IMealRecordDao mealRecordDao;
	
	@Autowired
	private ITravelAccountFlowService travelAccountFlowService;
	
	@Autowired
	public void setDao(IMealRecordDao dao) {
		this.dao = dao;
		this.mealRecordDao =dao;
	}

	@Override
	public List<MealRecordView> queryAll(Date startDate, Date endDate) {
		return mealRecordDao.queryAll(startDate,endDate);
	}

	@Override
	public OrderDishesView orderDishes(OrderDishesView view) {
		TravelAccountFlow flow = travelAccountFlowService.recordFlow(view.getTravelAccountFlow());
		for(MealRecord mRecord : view.getMealRecordList()){
			mRecord.setTravelAccountFlow(flow);
		}
		save(view.getMealRecordList());
		return view;
	}

	@Override
	public List<MealRecordDetailView> queryOnePerson(Date startDate, Date endDate, Long pkConsumerAccount) {
		return mealRecordDao.queryOnePerson(startDate,endDate,pkConsumerAccount);
	}
}
